package com.component.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.component.domain.MUserToken;
import com.component.service.MUserTokenService;
import com.component.mapper.MUserTokenMapper;
import org.apache.ibatis.annotations.CacheNamespace;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 *
 */
@CacheConfig(cacheNames = "MUserTokenServiceImpl")
@Service
public class MUserTokenServiceImpl extends ServiceImpl<MUserTokenMapper, MUserToken>
    implements MUserTokenService{

    @Cacheable(cacheNames = "getMuserTokenByToken",key = "#token")
    @Override
    public MUserToken getMuserTokenByToken(String token) {
        LambdaQueryWrapper<MUserToken> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(MUserToken::getToken,token);
        MUserToken mUserToken=this.baseMapper.selectOne(lambdaQueryWrapper);
        return mUserToken;
    }

    @CacheEvict(cacheNames = "getMuserTokenByToken",key = "#token")
    @Override
    public MUserToken removTokenByToken(String token) {
        LambdaQueryWrapper<MUserToken> muserToken=new LambdaQueryWrapper<>();
        this.baseMapper.delete(muserToken);
        return null;
    }
}




